//
//  Student.m
//  OC9_内存
//
//  Created by dllo on 15/11/5.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "Student.h"

@implementation Student
@synthesize name = _name;
@synthesize age = _age;
@synthesize sex = _sex;

// 重写dealloc方法,将retain/copy声明的实例变量都release在方法内
// 为了解决setter方法引入的引用计数加1的遗留问题
- (void)dealloc
{
    
    // 当减1的时候最好不要调用getter方法
    [_name release];
    [super dealloc];
}


- (NSString *)name
{
    return [[_name retain] autorelease];
}

- (void)setName:(NSString *)name
{
    if (!(name == _name)) {
        [_name release];
        _name = [name retain];
    }
}


- (NSInteger)age
{
    return _age;
}

- (void)setAge:(NSInteger)age
{
    _age = age;
}


- (NSString *)sex
{
    return [[_sex retain] autorelease];
}


- (void)setSex:(NSString *)sex
{
    if (!(sex == _sex)) {
        [_sex release];
        _sex = [sex copy];
    }
}



@end
